package com.wing.productionPlan.controller.app;

import com.wing.common.utils.PageResult;
import com.wing.productionPlan.model.response.UnstartedMaterialsVO;
import com.wing.productionPlan.service.SimpleWorkOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Validated
@Api(value = "App-未开工物料统计", tags = "未开工物料统计")
@RestController("unStartMaterialsController")
@RequestMapping("productionPlan/app/unStartMaterials")
@RequiredArgsConstructor
public class UnStartMaterialsController {
    private final SimpleWorkOrderService simpleWorkOrderService;


    @ApiOperation(value = "未开工物料统计列表", notes = "搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "第几页", defaultValue = "1", example = "1", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "limit", value = "每页多少条", defaultValue = "10", example = "10", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "sort", value="排序字段名", defaultValue = "materialSkuCode", example = "materialSkuCode", dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "order", value="排序规则(asc:正序, desc:倒序)", defaultValue = "asc", example = "asc", dataType = "String", paramType = "query")
    })
    @GetMapping("/list")
    public PageResult<UnstartedMaterialsVO> list(
            @RequestParam(defaultValue = "1") Integer page
            ,@RequestParam(defaultValue = "10") Integer limit
            ,@RequestParam(defaultValue = "materialSkuCode") String sort
            ,@RequestParam(defaultValue = "asc") String order
            ,String skuName
            ,String oldSpecCode
            ,String materialSkuCode
            ,String supplierName
            ,String brandName
            ,String query
    ){

        Map<String, Object> params = new HashMap<>();
        //排序
        if (StringUtils.isNotBlank(sort) && StringUtils.isNotBlank(order)) {
            params.put("sort",sort);
            params.put("order",order);
        }
        if (StringUtils.isNotBlank(skuName)){
            params.put("skuName",skuName);
        }
        if (StringUtils.isNotBlank(oldSpecCode)){
            params.put("oldSpecCode",oldSpecCode);
        }
        if (StringUtils.isNotBlank(materialSkuCode)){
            params.put("materialSkuCode",materialSkuCode);
        }
        if (StringUtils.isNotBlank(supplierName)){
            params.put("supplierName",supplierName);
        }
        if (StringUtils.isNotBlank(brandName)){
            params.put("brandName",brandName);
        }
        if (StringUtils.isNotBlank(query)){
            params.put("query",query);
        }
        return simpleWorkOrderService.listUnstartedMaterials(page,limit,params);
    }

}
